if(!dojo._hasResource["market.widgets.component.ShowPictures"]){
dojo._hasResource["market.widgets.component.ShowPictures"]=true;
require(["dojo/_base/declare","market/widgets/CommonWidget","dojox/image/Lightbox","dojo/dom","dojo/query","dojo/window","dojo/dom-construct"],function(declare,CommonWidget,Lightbox,dom,query,win,contruct){
declare("market.widgets.component.ShowPictures",[CommonWidget],{
_templHtml:'<div style="padding:5px;"><div class="submenu_nobg">{actions}<a href="#"><img alt="" src="../images/back.png" id="btnBack"/></a></div><div class="clear"></div>{pictures}</div><div class="clear"></div>',
_pictureHtml:'<div class="border_pic_thin"><a href="#" name="href_lightbox_picture"><input type="hidden" value="getContent/{UUID}"><img alt="{comment}" src="getContent/{UUID}/medium" width="159"/></a>{picTitle}</div>',
_picTitleHtml:'<div style="padding-left:5px;">{chkHtml} {comment}</div>',
_chkAttHtml:'<input dojoType="dijit.form.CheckBox" value="{UUID}" name="chkAttacedUUID" checked="false"/>',
_btnAttachedHtml:'<a href="#"><img alt="" src="images/valid.png" id="btnOk"/></a>',
albumUUID:null,lightboxDialog:null,_currentGenericForm:null,hasAttached:false,
showPictures:function(){
   var args = {ajaxUrl:'getFile/'+this.albumUUID+'/pictures', callback:function(data){
      SYSTEMWIDGET.showPictures().parseContent(data);
   }};
   SYSTEMWIDGET.ajaxWidget(args).callXhrGetJson();
},
parseContent:function(data){
   var lightbox = this._getLightboxDialog();
   var picturesHTML = '';
   var colDivs=[];
   var cols=this._cols()-1;
   var colIndex=0;
   for (var index=0; index<data.length; index++){
      var pic = data[index];
      var chkHtml='';
      if (this.hasAttached){
         chkHtml=dojo.replace(this._chkAttHtml,pic);
      }
      pic.chkHtml=chkHtml;
      pic.picTitle=dojo.replace(this._picTitleHtml,pic);
      var picHtml = dojo.replace(this._pictureHtml,pic);
      lightbox.addImage({title:pic.comment,href:"getContent/"+pic.UUID},this.albumUUID);
      if (colIndex<cols){
         var colVal=colDivs[colIndex];
         colDivs[colIndex]=(colVal==null?"":colVal)+picHtml;
         colIndex++;
      }else
         colIndex=0;
   }
   for(var index=0;index<colDivs.length;index++){
      picturesHTML+='<div class="box_picture_view">'+colDivs[index]+'</div>';
   }
   var actionsHTML = '';
   if (this.hasAttached)
      actionsHTML = this._btnAttachedHtml;
   dojo.html.set(dom.byId(this.contentId), dojo.replace(this._templHtml,{pictures:picturesHTML,actions:actionsHTML}),{parseContent: true});
   query('a[name="href_lightbox_picture"]').onclick(function(){
      var hrefViewPicture = dojo.query('input[type="hidden"]', this)[0].value;
      SYSTEMWIDGET.showPictures().showLightboxDialog(hrefViewPicture);
   });
   query('#btnBack').onclick(function(){
      SYSTEMWIDGET.album().showAlbums();
   });
   query('#btnOk').onclick(function(){
      SYSTEMWIDGET.album().attachPictures();
   });
},
selectedFiles:function(){
   var _selectedFiles = new Array();
   dojo.forEach(query('input[name="chkAttacedUUID"]:checked'),
      function(selectTag){
         _selectedFiles.push(selectTag.value);
      }
    );
   return _selectedFiles;
},
showLightboxDialog:function(hrefViewPicture){
   this.lightboxDialog.show({group:this.albumUUID, href:hrefViewPicture});
},
_cols:function(){
   return win.getBox().w/174;
},
_getLightboxDialog:function(){
   if (this.lightboxDialog == null){
      this.lightboxDialog = new dojox.image.LightboxDialog({});
      this.lightboxDialog.startup();
   }
   this.lightboxDialog.removeGroup(this.albumUUID);
   return this.lightboxDialog;
}
});});}


